package cn.alusiaor.nacosdiscoveryclientcommom.controller;


import cn.alusiaor.nacosdiscoveryclientcommom.config.DemoConfig;
import cn.alusiaor.nacosdiscoveryclientcommom.feignclient.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhuzhiping
 */
@Slf4j
@RestController
@RefreshScope
public class TestController {

    @Qualifier("nacos-discovery-client-provider")
    @Autowired
    private UserService userService;

    @Value("${common:null}")
    private String common;

    @Value("${ext1:null}")
    private String ext1;

    @Value("${ext2:null}")
    private String ext2;

    @GetMapping("/hello")
    public String hello(@RequestParam String name) {
        String result = userService.callHello(name);
        log.info(" return :{} ", result);
        return " return : " + result;
    }


    @GetMapping("/multi")
    public String multiConfig() {
        int i = 1 / 0;
        return String.format("common: %s ,ext1: %s ,ext2: %s ,configName: %s", common, ext1, ext2, DemoConfig.getName());
    }

}
